﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace LandandSurvey
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load( object sender, EventArgs e )
        {
            if ( HasPermission( txtUserName.Text, txtPassword.Text ) )
            {
                Session[ "user.loggedin" ] = "true";
                Session[ "user.name" ] = txtUserName.Text;
                Response.Redirect( Request[ "returnurl" ] );
            }
        }

        public bool HasPermission( string username, string password )
        {
            landsdbEntities container = new landsdbEntities();
            AppUser user = ( from i in container.AppUsers
                             where i.UserName == username
                             select i ).ToList().FirstOrDefault();
            if ( user != null )
            {
                if ( user.Password == password )
                {
                    return true;
                }
            }
            return false;
        }
    }
}